//
//  AsynCell.m
//  Demo
//
//  Created by lx on 2018/12/26.
//  Copyright © 2018 mgz. All rights reserved.
//

#import "AsynCell.h"

@implementation AsynCell

- (instancetype)initWithAsynModel:(AsynModel *)model{
    if (self = [super init]) {
        self.backgroundColor = [UIColor colorWithRed:243/255.0 green:244/255.0 blue:245/255.0 alpha:1.0];
        _model = model;
        _bigImg = [[ASNetworkImageNode alloc]init];
        
        
        [self addSubnode:_bigImg];
        _bigImg.image = [UIImage imageNamed:@"bg"];
        
        _txImg = [[ASImageNode alloc]init];
        [self addSubnode:_txImg];
        _txImg.image = [UIImage imageNamed:@"ic_system2"];
        
        _titleLab = [[ASTextNode alloc]init];
        _titleLab.maximumNumberOfLines = 0;
        
        _titleLab.style.flexShrink = YES;
        
        [self addSubnode:_titleLab];
        _titleLab.attributedText =  [[NSMutableAttributedString alloc] initWithString:@"我是一条系统消息，我是一条系统消息，我是一条系统消息，我是一条系统消息，我是一条系统消息，我是一 条系统消息，我是一条系统消息，我是一条系统消息。" attributes: @{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size: 16],NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]}];
        _timeLab = [[ASTextNode alloc]init];
        [self addSubnode:_timeLab];
        
        _timeLab.attributedText =  [[NSMutableAttributedString alloc] initWithString:@"今天 上午12:00" attributes: @{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size: 12],NSForegroundColorAttributeName: [UIColor colorWithRed:119/255.0 green:119/255.0 blue:119/255.0 alpha:1.0]}];
        
        
        _redLab = [[ASTextNode alloc]init];
        [self addSubnode:_redLab];
        
        _redLab.attributedText =  [[NSMutableAttributedString alloc] initWithString:@"点击查看"attributes: @{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size: 16],NSForegroundColorAttributeName: [UIColor colorWithRed:170/255.0 green:170/255.0 blue:170/255.0 alpha:1.0]}];
        
        

    }
    return self;
}

- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize{
    
    UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 0, 0);
    ASInsetLayoutSpec *inset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets
                                                                      child:_timeLab];
    ASCenterLayoutSpec *timeSpec = [ASCenterLayoutSpec centerLayoutSpecWithCenteringOptions:ASCenterLayoutSpecCenteringX sizingOptions:ASCenterLayoutSpecSizingOptionMinimumY child:inset];
    _titleLab.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0);
    _bigImg.style.preferredSize = CGSizeMake(270, 160);
    _txImg.style.preferredSize = CGSizeMake(40, 40);
    
    ASStackLayoutSpec *contentSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:5 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStart children:@[_bigImg,_titleLab,_redLab]];
    contentSpec.style.flexShrink = YES;
    ASStackLayoutSpec *leftSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal spacing:16 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStart children:@[_txImg,contentSpec]];
    leftSpec.style.flexShrink = YES;
    ASStackLayoutSpec *IMGContentSpec = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionVertical spacing:16 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsStart children:@[timeSpec,leftSpec]];//小图加文本在上  大图在下
    IMGContentSpec.style.flexShrink = YES;
    return [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(13, 16, 20, 33) child:IMGContentSpec];
    
}


@end
